﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FTchina;

public partial class UI_del : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        basic.CheckAdmin(this);
        basic.ChkPoewr(this, FTchina.Api.htmlpath.GetCurrentPagePath());
        System.Collections.Specialized.NameValueCollection ServerVariables = System.Web.HttpContext.Current.Request.ServerVariables;

        string strvpage = (ServerVariables["HTTP_REFERER"] != null) ? ServerVariables["HTTP_REFERER"].ToString() : "";
        string strdome = ServerVariables["SERVER_NAME"].ToString();
        //if (!basic.GetSiteUrl().Contains(strdome))
        //{
        //    LogNet.LogBLL.warn("用户:" + basic.GetUserIp(this) + "从非本站地址访问删除页面");

        //    Response.Write("不允许直接访问本页面");
        //    Response.End();
        //    return;
        //}

        if (strvpage == "")
        {
            LogNet.LogBLL.warn("用户:" + basic.GetUserIp(this) + "非法访问删除页面");

            Response.Write("不允许直接访问本页面");
            Response.End();
            return;
        }
        string table = basic.SafeRequest(Request["t"]);
        string id = basic.SafeRequest(Request["id"]);
        if (table == "" || id == "") return;
        else
        {
            if (ChkDeleteable(table, id))
            {
                string DelSql = "delete from " + table + " where id=" + id;
                if (shujuku.ExecuteSql(DelSql))
                {
                    LogNet.LogBLL.info("用户:" + FTchina.Library.MasterHelper.MasterName + "删除表" + table + "系统编号" + id + "的信息");
                }
            }
            else
            {
                LogNet.LogBLL.info("用户:" + FTchina.Library.MasterHelper.MasterName + "删除表" + table + "系统编号" + id + "不能删除");

            }
            Response.Redirect(strvpage);
        }
    }




    /// <summary>
    /// 查看是否能够删除
    /// </summary>
    /// <param name="table"></param>
    /// <param name="id"></param>
    /// <returns>true 可删除，false 不可删</returns>
    protected Boolean ChkDeleteable(string table, string id)
    {
        bool flag = true;


        //系统管理员组不能删除
        if ((table.ToLower() == "usergroup") && (id == "1"))
        {
            flag = false;
        }

        return flag;
    }
}
